﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using infoMngmntGUI.View;
using infoMngmntGUI.Control;
using System.Data;

namespace infoMngmntGUI.View
{
    /// <summary>
    /// Interaction logic for Search_Patient.xaml
    /// </summary>
    public partial class AddVisit : IView
    {
        public AddVisit()
        {
            minimumAccess = Control.AccessManagement.UserType.NURSE;
            InitializeComponent();

            ComboBox_Doctor.ItemsSource = DbConnection.GetDoctors();
            ComboBox_Nurse.ItemsSource = DbConnection.GetNurses();
            ComboBox_Patient.ItemsSource = DbConnection.GetPatients();
        }

        public override string ToString()
        {
            return "Visit";
        }

   
        /*
         * Checks name inputs against a regular expression; if the input is valid, the method returns true and 
         * the program continues.  If input doesn't match the regex (contains a number in the name, for example), 
         * then the user is notified with a MessageBox, and the query is halted.
         */
        private bool IsValidInput()
        {

            if (ComboBox_Doctor.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select a Doctor",
                    "Invalid name", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                return false;
            }

            if (ComboBox_Nurse.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select a Doctor",
                    "Invalid name", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                return false;
            }

            if (ComboBox_Patient.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select a Doctor",
                    "Invalid name", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                return false;
            }

            if (!Regex.IsMatch(Text_temprature.Text, @"(^[0-9]+)") || !Regex.IsMatch(Text_pulse.Text, @"(^[0-9]+)"))
            {
                MessageBox.Show("The Temprature and Pulse must only contain Numbers and be between 1-3 numbers in length.",
                    "Invalid name", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                return false;
            }

            if (dobDatePicker.Text != "")
            {
                DateTime selectedDate;
                if (!DateTime.TryParse(dobDatePicker.ToString(), out selectedDate))
                {
                    MessageBox.Show("The selected date is not recognized as a valid date.",
                        "Invalid date", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                    return false;
                }
            }
            return true;
        }


        private void AddVisitButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsValidInput())
            {
                
            }
        }
    }
}
